﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>公告分类管理</title>
    <link href="~/Scripts/jquery-easyui-1.4.4/themes/bootstrap/easyui.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-easyui-1.4.4/jquery.min.js"></script>
    <script src="~/Scripts/jquery-easyui-1.4.4/jquery.easyui.min.js"></script>
    <script src="~/Scripts/jquery-easyui-1.4.4/locale/easyui-lang-zh_CN.js"></script>
    <link href="~/Content/themes/icon.css" rel="stylesheet" />
    <script src="~/Content/js/common.js"></script>
    <link href="~/Content/themes/table.css" rel="stylesheet" />
    <script type="text/javascript">
        $(function () {
            $.ajax({     //请求当前用户可以操作的按钮
                url: "/Button/GetUserAuthorizeButton?r=" + Math.random(),
                type: "post",
                data: { "KeyCode": "NewsType", "KeyName": "NewsType" },
                dataType: "json",
                timeout: 5000,
                success: function (data) {
                    if (data.success) {
                        var toolbar = getToolBar(data);      //common.js
                        if (data.search) {     //判断是否有浏览权限
                            $("#ui_NewsType_dg").datagrid({       //初始化datagrid
                                url: "/NewsType/GetAllNewsTypeInfo",
                                striped: true, rownumbers: true, pagination: true, pageSize: 20, singleSelect: true, multiSort: false,
                                idField: 'id',
                                sortName: 'fsort',
                                sortOrder: 'asc',
                                pageList: [20, 40, 60, 80, 100],
                                frozenColumns: [[
                                                //{ field: 'ck', checkbox: true },
                                                { field: 'id', title: '类型ID', width: 60 },
                                                { field: 'ftypename', title: '类型名称', width: 100 }]],
                                columns: [[
                                           { field: 'fsort', title: '排序', sortable: true, width: 80 },
                                           { field: 'CreateBy', title: '创建人', width: 80 },
                                           { field: 'CreateTime', title: '创建时间', width: 120 },
                                           { field: 'UpdateBy', title: '最后更新人', width: 130 },
                                           { field: 'UpdateTime', title: '最后更新时间', width: 150 }
                                ]],
                                toolbar: toolbar.length == 0 ? null : toolbar
                            });
                        }
                        else {
                            $.show_alert("提示", "无权限，请联系管理员！");
                        }
                    } else {
                        $.show_alert("错误", data.result);
                    }
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    if (textStatus == "timeout") {
                        $.show_alert("提示", "请求超时，请刷新当前页重试！");
                    }
                    else {
                        $.show_alert("错误", textStatus + "：" + errorThrown);
                    }
                }
            })

            //回车搜索
            $("#ui_NewsType_search").find('input').on('keyup', function (event) {
                if (event.keyCode == '13') {
                    searchdata();
                }
            })
        });

        //新增
        function AddNewsType() {
            $("<div/>").dialog({
                id: "ui_NewsType_add_dialog",
                href: "/NewsType/NewsTypeAdd",
                title: "添加公告分类",
                height: 200,
                width: 400,
                modal: true,
                buttons: [{
                    id: "ui_NewsType_add_btn",
                    text: '添 加',
                    handler: function () {
                        $("#NewsTypeAddForm").form("submit", {
                            url: "/NewsType/AddNewsType",
                            onSubmit: function (param) {
                                param.TypeName = $("#txtTypeName").val();
                                param.Sort = $('#txtSort').val();
                                if ($(this).form('validate')) {
                                    $('#ui_NewsType_edit_btn').linkbutton('disable');
                                    return true;
                                }
                                else {
                                    $('#ui_NewsType_add_btn').linkbutton('enable');
                                    return false;
                                }
                            },
                            success: function (data) {
                                var dataJson = eval('(' + data + ')');
                                if (dataJson.success) {
                                    $("#ui_NewsType_add_dialog").dialog('destroy');
                                    $.show_alert("提示", dataJson.msg);
                                    $("#ui_NewsType_dg").datagrid("reload");
                                } else {
                                    $('#ui_NewsType_add_btn').linkbutton('enable');
                                    $.show_alert("提示", dataJson.msg);
                                }
                            }
                        });
                    }
                }, {
                    text: '取 消',
                    handler: function () {
                        $("#ui_NewsType_add_dialog").dialog('destroy');
                    }
                }],
                onLoad: function () {
                    $("#txtTypeName").focus();
                },
                onClose: function () {
                    $("#ui_NewsType_add_dialog").dialog('destroy');  //销毁dialog对象
                }
            });
        }

        //修改
        function EditNewsType() {
            var row = $("#ui_NewsType_dg").datagrid("getChecked");
            if (row.length < 1) {
                $.show_alert("提示", "请先选择要修改的公告分类");
                return;
            }
            $("<div/>").dialog({
                id: "ui_NewsType_edit_dialog",
                href: "/NewsType/NewsTypeEdit",
                title: "修改公告分类",
                height: 200,
                width: 400,
                modal: true,
                buttons: [{
                    id: "ui_NewsType_edit_btn",
                    text: '修 改',
                    handler: function () {
                        $("#NewsTypeEditForm").form("submit", {
                            url: "/NewsType/EditNewsType",
                            onSubmit: function (param) {
                                param.id = $("#hidid").val();
                                param.originalName = $("#hidoriginalName").val();
                                param.TypeName = $("#txtTypeName").val();
                                param.Sort = $('#txtSort').val();
                                if ($(this).form('validate')) {
                                    $('#ui_NewsType_add_btn').linkbutton('disable');
                                    return true;
                                }
                                else {
                                    $('#ui_NewsType_edit_btn').linkbutton('enable');
                                    return false;
                                }
                            },
                            success: function (data) {
                                var dataJson = eval('(' + data + ')');
                                if (dataJson.success) {
                                    $("#ui_NewsType_edit_dialog").dialog('destroy');
                                    $.show_alert("提示", dataJson.msg);
                                    $("#ui_NewsType_dg").datagrid("reload");
                                } else {
                                    $('#ui_NewsType_edit_btn').linkbutton('enable');
                                    $.show_alert("提示", dataJson.msg);
                                }
                            }
                        });
                    }
                }, {
                    text: '取 消',
                    handler: function () {
                        $("#ui_NewsType_edit_dialog").dialog('destroy');
                    }
                }],
                onLoad: function () {
                    $("#hidid").val(row[0].id);
                    $("#hidoriginalName").val(row[0].ftypename);
                    $("#txtTypeName").val(row[0].ftypename);
                    $('#txtSort').numberspinner('setValue', row[0].fsort);
                },
                onClose: function () {
                    $("#ui_NewsType_edit_dialog").dialog('destroy');
                }
            });
        }

        //删除
        function DelNewsType() {
            var rows = $("#ui_NewsType_dg").datagrid("getChecked");
            if (rows.length < 1) {
                $.show_alert("提示", "请先勾选要删除的公告分类");
                return;
            }
            $.messager.confirm('提示', '确定删除选中行吗？', function (r) {
                if (r) {
                    var NewsTypeIDs = "";
                    $.each(rows, function (i, row) {
                        NewsTypeIDs += row.id + ",";
                    });
                    NewsTypeIDs = NewsTypeIDs.substring(0, NewsTypeIDs.length - 1);
                    $.ajax({
                        url: "/NewsType/DelNewsTypeByIDs",
                        data: {
                            IDs: NewsTypeIDs
                        },
                        type: "POST",
                        dataType: "json",
                        success: function (data) {
                            if (data.success) {
                                $.show_alert("提示", data.msg);
                                $("#ui_NewsType_dg").datagrid("reload").datagrid('clearSelections').datagrid('clearChecked');
                            } else {
                                $.show_alert("提示", data.msg);
                            }
                        }
                    });
                }
            });
        }

        //搜索
        function searchdata() {
            $("#ui_NewsType_dg").datagrid('load', {
                FTypeName: $("#txtSearchFTypeName").val()
            });
            $("#ui_NewsType_dg").datagrid('clearSelections').datagrid('clearChecked');
        }

    </script>

</head>
<body>
    <div id="ui_NewsType_layout" class="easyui-layout" data-options="fit:true,border:false">
        <div data-options="region:'north',split:true,border:true,collapsed:false" title="搜索条件" style="height:72px;">
            <div id="ui_NewsType_search">
                <table class="tableForm" style="height: 28px; background: #f5f5f5;">
                    <tr>
                        <th height="20px">
                            类型名称：
                        </th>
                        <td>
                            <input name="txtSearchFTypeName" id="txtSearchFTypeName" class="easyui-validatebox textbox" style="width:150px;height:22px;" />
                        </td>
                        <td>
                            <a href="javascript:void(0);" class="easyui-linkbutton" iconcls="icon-search" plain="true"
                               onclick="searchdata();">搜索</a>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div data-options="region:'center',border:false">
            <table id="ui_NewsType_dg" data-options="fit:true,border:false"></table>
        </div>
    </div>

</body>
</html>
